package com.ocp.macro.enums;

/**
 * 状态码设计
 */
public enum DataCode {
    /* 通用状态：100~200 */
    SUCCESS(100, "成功"),
    FAIL(102, "失败"),
    WARNING(103, "警告"),
    ERROR(104, "错误"),

    /* 参数错误：600～700 */
    PARAM_NOT_VALID(600, "参数无效"),
    PARAM_IS_BLANK(601, "参数为空"),
    PARAM_TYPE_ERROR(602, "参数类型错误"),
    PARAM_NOT_COMPLETE(603, "参数缺失"),

    /* 业务错误 : 700~800 */
    NO_PERMISSION(701, "没有权限"),
    NO_LOGIN(702, "没有登录"),
    TOKEN_ERROR_EXPIRE(703, "信息验证错误"),
    ACCOUNT_LOCK(704, "账号锁定"),
    ACCOUNT_LOGIN_FAIL(705, "账号登录失败"),
    NO_USER_MESSAGE(707, "用户信息不存在"),
    SEND_EMAIL_FAIL(708, "邮件发送失败"),
    VERIFY_CODE_EXPIRE(709,"验证码过期"),
    ACCOUNT_DISABLE(710, "账号被禁用"),
    ACCOUNT_IS_HAVE(711, "账号已存在"),

    /* mysql异常状态 800~900*/
    MODIFY_EXCEPTION(800, "修改数据异常"),
    INSERT_EXCEPTION(801, "插入数据异常"),
    DELETE_EXCEPTION(802, "删除数据异常"),
    SELECT_EXCEPTION(803, "查询数据异常");

    private Integer code;
    private String message;

    private DataCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * 根据code获取message
     */
    public static String getMessageByCode(Integer code) {
        for (DataCode ele : values()) {
            if (ele.getCode().equals(code)) {
                return ele.getMessage();
            }
        }
        return null;
    }
}
